package study.day6.t8;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

public class T8 {
    public static void main(String[] args) {
        Map<String, Book> map=new HashMap<String, Book>();
        Book b1=new Book("你是人间的四月天",60,"林徽因");
        Book b2=new Book("活着",80,"余华");
        map.put(b1.getName(), b1);
        map.put(b2.getName(), b2);
        //获取所有Key的集合
        Set<String> keys=map.keySet();
        for(String key:keys){
            Book value = map.get(key);
            System.out.println(key+"\t"+value.getAuthor());
        }
        System.out.println("=========================");
        //打印所有元素,获取所有值的集合
        Collection<Book> values = map.values();
        for(Book value:values){
            System.out.println(value.getName()+"\t"+value.getAuthor());
        }
        System.out.println("=========================");
        //获取key和value的集合，entry
        Set<Map.Entry<String, Book>> entries = map.entrySet();
        for(Map.Entry<String, Book> entry:entries){
            System.out.println(entry.getKey()+"\t"+entry.getValue().getAuthor());
        }
        System.out.println("=========================");
        //*通过stream方式进行遍历
        Stream<Map.Entry<String, Book>> stream = map.entrySet().stream();
        stream.forEach(entry-> System.out.println(entry.getKey()+"\t"+entry.getValue().getAuthor()));

    }
}
